commonlibsse_ng\re\m/
MemoryManager.rs1pub mod SimpleArray;
2pub mod alloc;
3
4pub use self::alloc::tes_global::TESGlobalAlloc;
5
6use core::ffi::c_void;
7use core::ptr;
8
9use crate::re::BSSmallBlockAllocator::BSSmallBlockAllocator;
10use crate::re::CompactingStore;
11use crate::re::IMemoryHeap::IMemoryHeap;
12use crate::re::ScrapHeap::ScrapHeap;
13
14#[repr(C)]
16pub struct ThreadScrapHeap {
17 pub heap: ScrapHeap, pub next: *mut ThreadScrapHeap, pub owningThread: u32, pub pad: u32, }
22const _: () = assert!(core::mem::size_of::<ThreadScrapHeap>() == 0xA0);
23
24#[repr(C)]
26#[derive(Debug)]
27pub struct MemoryManager {
28 pub initialized: bool, pub numHeaps: u16, pub numPhysicalHeaps: u16, pub heaps: *mut *mut IMemoryHeap, pub allowOtherContextAllocs: *mut bool, pub heapsByContext: [*mut IMemoryHeap; 127], pub threadScrapHeap: *mut ThreadScrapHeap, pub physicalHeaps: *mut *mut IMemoryHeap, pub bigAllocHeap: *mut IMemoryHeap, pub emergencyHeap: *mut IMemoryHeap, pub smallBlockAllocator: *mut BSSmallBlockAllocator, pub compactingStore: *mut CompactingStore::Store, pub externalHavokAllocator: *mut IMemoryHeap, pub specialHeaps: bool, pub allowPoolUse: bool, pub pad44A: [u8; 2], pub sysAllocBytes: u32, pub mallocBytes: u32, pub alignmentForPools: u32, pub mainThreadMemoryProblemPassSignal: u32, pub failedAllocationSize: usize, pub numMemoryProblemPassesRun: u32, pub timeOfLastMemoryProblemPass: usize, pub defaultHeap: *mut IMemoryHeap, }
53const _: () = assert!(core::mem::size_of::<MemoryManager>() == 0x480);
54
55impl Default for MemoryManager {
56 #[inline]
57 fn default() -> Self {
58 Self::new()
59 }
60}
61
62impl MemoryManager {
63 #[inline]
64 pub const fn new() -> Self {
65 Self {
66 initialized: false,
67 numHeaps: 0,
68 numPhysicalHeaps: 0,
69 heaps: ptr::null_mut(),
70 allowOtherContextAllocs: ptr::null_mut(),
71 heapsByContext: [ptr::null_mut(); 127],
72 threadScrapHeap: ptr::null_mut(),
73 physicalHeaps: ptr::null_mut(),
74 bigAllocHeap: ptr::null_mut(),
75 emergencyHeap: ptr::null_mut(),
76 smallBlockAllocator: ptr::null_mut(),
77 compactingStore: ptr::null_mut(),
78 externalHavokAllocator: ptr::null_mut(),
79 specialHeaps: false,
80 allowPoolUse: true,
81 pad44A: [0; 2],
82 sysAllocBytes: 0,
83 mallocBytes: 0,
84 alignmentForPools: 0,
85 mainThreadMemoryProblemPassSignal: 0,
86 failedAllocationSize: 0,
87 numMemoryProblemPassesRun: 0,
88 timeOfLastMemoryProblemPass: 0,
89 defaultHeap: ptr::null_mut(),
90 }
91 }
92
93 #[commonlibsse_ng_derive_internal::relocate_fn(se_id = 11045, ae_id = 11141)]
94 pub unsafe fn GetSingleton() -> *mut MemoryManager {}
95
96 #[commonlibsse_ng_derive_internal::relocate_fn(se_id = 66859, ae_id = 68115)]
98 pub unsafe fn Allocate(
99 &mut self,
100 size: usize,
101 alignment: i32,
102 alignment_required: bool,
103 ) -> *mut c_void {
104 }
105
106 #[commonlibsse_ng_derive_internal::relocate_fn(se_id = 66861, ae_id = 68117)]
108 pub unsafe fn Deallocate(&mut self, mem: *mut c_void, alignment_required: bool) {}
109
110 #[commonlibsse_ng_derive_internal::relocate_fn(se_id = 66841, ae_id = 68088)]
112 pub unsafe fn GetThreadScrapHeap(&mut self) -> *mut ScrapHeap {}
113
114 #[commonlibsse_ng_derive_internal::relocate_fn(se_id = 66860, ae_id = 68116)]
116 pub unsafe fn Reallocate(
117 &mut self,
118 old_mem: *mut c_void,
119 new_size: usize,
120 alignment: i32,
121 aligned: bool,
122 ) -> *mut c_void {
123 }
124
125 #[commonlibsse_ng_derive_internal::relocate_fn(se_id = 35199, ae_id = 36091)]
127 pub unsafe fn RegisterMemoryManager(&mut self) {}
128}
129
130#[inline]
132pub unsafe fn malloc(size: usize) -> *mut c_void {
133 unsafe { MemoryManager::GetSingleton().as_mut() }
134 .map_or(ptr::null_mut(), |heap| unsafe { heap.Allocate(size, 0, false) })
135}
136
137#[inline]
139pub unsafe fn free(ptr: *mut c_void) {
140 unsafe {
141 if let Some(heap) = MemoryManager::GetSingleton().as_mut() {
142 heap.Deallocate(ptr, false);
143 };
144 }
145}